<template>
    <transition name="fade">
        <div
            v-if="visible"
            class="popup-wrapper"
        >
            <div
                class="popup"
                :style="{ height: typeof height === 'string' ? height : `${height}px` }"
            >
                <slot></slot>
            </div>
        </div>
    </transition>
</template>

<script>
export default {
    name: 'Popup',
    components: {},
    props: {
        value: {
            type: Boolean,
            default: false,
        },
        height: {
            type: [String, Number],
            default: 'auto',
        },
    },
    data() {
        return {
            visible: this.value,
        };
    },
    computed: {},
    watch: {
        value(val) {
            this.visible = val;
        },
        visible(val) {
            this.$emit('input', val);
        },
    },
    mounted() {},
    methods: {},
};
</script>

<style scoped>
.popup-wrapper {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
}

.popup {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300px;
    padding: 20px 10px;
    border-radius: 10px;
    background-color: #fff;
    transform: translate(-50%, -50%);
    transition: all 0.5s;
}

.fade-enter-active {
    transition: opacity 0.2s;
}

.fade-leave-active {
    transition: opacity 0.2s 0.1s;
}

.fade-enter,
.fade-leave-to {
    opacity: 0;
}

.fade-enter-active .popup {
    transition: all 0.3s 0.1s;
}

.fade-leave-active .popup {
    transition: all 0.3s;
}

.fade-enter .popup,
.fade-leave-to .popup {
    opacity: 0;
    top: 100%;
    width: 150px;
}
</style>
